package com.zahb.qadx.ui.fragment;

import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.zahb.qadx.R;
import com.zahb.qadx.base.BaseFragmentExt;
import com.zahb.qadx.util.CompatHelper;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Zdw on 2020/10/12 10:59
 * 首页公有布局
 */
public abstract class HomeFuncFragment extends BaseFragmentExt {

    @BindView(R.id.tv_title)
    TextView mTvTitle;
    @BindView(R.id.card_view)
    CardView mCardView;
    @BindView(R.id.recycler_view)
    RecyclerView mRecyclerView;
    public boolean open=true;

    // 隐藏卡片，排除边距
    void transparentCardView() {
        mCardView.setCardBackgroundColor(CompatHelper.getColor(R.color.transparent));
        mCardView.setCardElevation(0);
        ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) mRecyclerView.getLayoutParams();
        lp.setMargins(0, 0, 0, 0);
        mRecyclerView.setLayoutParams(lp);
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_home_func;
    }

    @Override
    protected void initViews(View rootView) {
        mUnbinder = ButterKnife.bind(this, rootView);
        mRecyclerView.setLayoutManager(getLayoutManager());
        RecyclerView.ItemDecoration decoration = getItemDecoration();
        if (decoration != null)
            mRecyclerView.addItemDecoration(decoration);
        mRecyclerView.setAdapter(getAdapter());
    }

    @NonNull
    abstract protected RecyclerView.LayoutManager getLayoutManager();

    @Nullable
    abstract protected RecyclerView.ItemDecoration getItemDecoration();

    @NonNull
    abstract protected RecyclerView.Adapter<BaseViewHolder> getAdapter();

    abstract protected void seeMore();

    @OnClick(R.id.tv_see_more)
    void onViewClicked() {
        seeMore();
    }
}
